<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">
<style>
    .readonly{background-color: #fafafa!important;}
</style>
<body class="optPage">
<div style="height: 45px"></div>
<div id="opt_nav">
</div>
<div id="dialog">
    <div class="page-title" id="page-title">
        <div class="page-title-con">
            <span class="title" id="titss"></span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
</div>
<?php include "dao.php"?>
<style>
    #commentForm .main-container .layui-form-item{
        padding: 0 200px;
    }
    .middput{text-align: center}
    .dankuai{width: calc(50% - 83px)!important;float: left!important;}
    .dannav4{width: calc(25% - 50.5px)!important;float: left!important;text-align: center;line-height: 37px;color:#777;}
    .dankuai4{width: calc(25% - 50.5px)!important;float: left!important;}
    #cuss tr th{font-weight: bold;}
</style>
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="main-container" style="padding: 0 0 20px 0 !important">

        <div class="block-generic">


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits" style="text-align: center;position: relative">
                        <span style="font-size: 20px"><b>工程概况</b></span>
                        <div id="edittitss" style="right:12px;position: absolute;top:3px;font-size: 13px"></div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>项目名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable  autocomplete="off" class="layui-input middput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">项目编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" id="number" placeholder="请输入" clearable  autocomplete="off" class="layui-input middput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">项目类型</label>
                        <div class="layui-input-block">
                            <div id="xiangtype"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">建筑面积（m2)</label>
                        <div class="layui-input-block">
                            <input type="text" name="mian" id="mian" placeholder="请输入"  autocomplete="off" readonly class="layui-input readonly middput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">项目地址</label>
                        <div class="layui-input-block dankuai" style="z-index: 1;margin-left: 0!important;">
                            <input type="text" name="areas" id="areas" placeholder="请选择" readonly clearable autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-block dankuai" style=";margin-left: 0!important;">
                            <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input middput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">工期</label>
                        <div class="layui-input-block">
                            <input type="text" name="duration" id="duration" placeholder="请输入" clearable  autocomplete="off" class="layui-input middput">
                        </div>
                    </div>
                </div>
            </div>



            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-block dannav4" style=";margin-left: 0!important;">面积（m2)</div>
                        <div class="layui-input-block dannav4" style=";margin-left: 0!important;">层数（不含机房层）</div>
                        <div class="layui-input-block dannav4" style=";margin-left: 0!important;">总高度 米（算至檐口）</div>
                        <div class="layui-input-block dannav4" style=";margin-left: 0!important;">层高*层数</div>
                    </div>
                </div>
            </div>
            <div id="qinginfo">
<!--                <div class="layui-form-item">-->
<!--                    <div class="layui-row layui-col-space10">-->
<!--                        <div class="layui-col-md12">-->
<!--                            <label class="layui-form-label">6AAA</label>-->
<!--                            <div class="layui-input-block dankuai4" style=";margin-left: 0!important;">-->
<!--                                <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input middput">-->
<!--                            </div>-->
<!--                            <div class="layui-input-block dankuai4" style=";margin-left: 0!important;">-->
<!--                                <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input middput">-->
<!--                            </div>-->
<!--                            <div class="layui-input-block dankuai4" style=";margin-left: 0!important;">-->
<!--                                <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input middput">-->
<!--                            </div>-->
<!--                            <div class="layui-input-block dankuai4" style=";margin-left: 0!important;">-->
<!--                                <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input middput">-->
<!--                            </div>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </div>-->
            </div>





            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">承包方式</label>
                        <div class="layui-input-block">
                            <input type="text" name="chengtype" id="chengtype" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">承包范围</label>
                        <div class="layui-input-block">
                            <textarea id="chengfan" name="chengfan" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">进度款支付</label>
                        <div class="layui-input-block">
                            <textarea id="jinfu" name="jinfu" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">调差</label>
                        <div class="layui-input-block">
                            <textarea id="diaocha" name="diaocha" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">违约责任</label>
                        <div class="layui-input-block">
                            <textarea id="weiyue" name="weiyue" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">资金成本</label>
                        <div class="layui-input-block">
                            <input type="text" name="zicheng" id="zicheng" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">成本数据来源</label>
                        <div class="layui-input-block">
                            <textarea id="chenglai" name="chenglai" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">业主情况</label>
                        <div class="layui-input-block">
                            <textarea id="yezhu" name="yezhu" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">投标报价建议</label>
                        <div class="layui-input-block">
                            <input type="text" name="toujian" id="toujian" placeholder="请输入" clearable  autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>


            <br>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">含税投标价(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="money" id="money" onkeyup="countTou()" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">税率(%)</label>
                        <div class="layui-input-block">
                            <input type="text" name="rate" id="rate" onkeyup="countTou()" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">税金(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="rate_money" id="rate_money" readonly placeholder="请输入" autocomplete="off" class="readonly layui-input moneyinput">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">不含税投标价(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="no_money" id="no_money" readonly placeholder="请输入" autocomplete="off" class="readonly layui-input moneyinput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">含税预算价(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="budget_money" id="budget_money" onkeyup="countShui()" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">税率(%)</label>
                        <div class="layui-input-block">
                            <input type="text" name="budget_rate" id="budget_rate" onkeyup="countShui()" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">税金(元)</label>
                        <div class="layui-input-block">
                            <input type="text" name="budget_rate_money" id="budget_rate_money" placeholder="请输入" readonly autocomplete="off" class="layui-input readonly moneyinput">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">不含税预算价(元)	</label>
                        <div class="layui-input-block">
                            <input type="text" name="budget_no_money" id="budget_no_money" placeholder="请输入" readonly  autocomplete="off" class="layui-input readonly moneyinput">
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <div style="text-align: center;margin-bottom: 100px;">
        <button type="button" class="layui-btn layui-btn-sm btn-dark marginr5" lay-submit="" lay-filter="add">提交</button>
    </div>

</form>
<script>
    var param_id = getQueryVariable('enginid') || 0;


    $("#commentForm").validate({
        rules: {
            name: {required: true},
        },
        messages:{
            name: {required: "请输入"},
        }
    });

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_main_gai_edit, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                $("#edittitss").html(res.data.edittitss);

                $("#name").val(data.name);
                $("#number").val(data.number);
                $("#xiangtype").val(data.xiangtype);
                $("#mian").val(data.mian);
                $("#areas").val(data.areas);
                $("#addr").val(data.addr);
                $("#duration").val(data.duration);
                $("#chengtype").val(data.chengtype);
                $("#chengfan").val(data.chengfan);
                $("#jinfu").val(data.jinfu);
                $("#diaocha").val(data.diaocha);
                $("#weiyue").val(data.weiyue);
                $("#zicheng").val(data.zicheng);
                $("#chenglai").val(data.chenglai);
                $("#yezhu").val(data.yezhu);
                $("#toujian").val(data.toujian);
                $("#money").val(data.money);
                $("#rate").val(data.rate);
                $("#rate_money").val(data.rate_money);
                $("#no_money").val(data.no_money);
                $("#budget_money").val(data.budget_money);
                $("#budget_rate").val(data.budget_rate);
                $("#budget_rate_money").val(data.budget_rate_money);
                $("#budget_no_money").val(data.budget_no_money);

                load_areas('areas', res.data.areas, 3);
                xmselect_dan('xiangtype', res.data.xiangtype, data.xiangtype);



                //
                //
                //
                //
                //
                //
                //
                //                            <div class="layui-input-block dankuai4" style=";margin-left: 0!important;">
                //                                <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input middput">
                //                            </div>
                //                            <div class="layui-input-block dankuai4" style=";margin-left: 0!important;">
                //                                <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input middput">
                //                            </div>
                //                            <div class="layui-input-block dankuai4" style=";margin-left: 0!important;">
                //                                <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input middput">
                //                            </div>

                var qing = res.data.qing;
                var str = '';
                for (var key in qing){
                    str += '<div class="layui-form-item"> <div class="layui-row layui-col-space10"><div class="layui-col-md12">';
                    str += '<label class="layui-form-label">'+qing[key].qingname+'</label>';

                    str += '<div class="layui-input-block dankuai4" style=";margin-left: 0!important;">';
                    str += '<input type="number" class="layui-input middput area" id="'+qing[key].id+'" value="'+qing[key].area+'" onkeyup="countqing(this)" placeholder="请输入" clearable autocomplete="off" >';
                    str += ' </div>';

                    str += '<div class="layui-input-block dankuai4" style=";margin-left: 0!important;">';
                    str += '<input type="number" class="layui-input middput storey" value="'+qing[key].storey+'" placeholder="请输入" clearable autocomplete="off" >';
                    str += ' </div>';

                    str += '<div class="layui-input-block dankuai4" style=";margin-left: 0!important;">';
                    str += '<input type="number" class="layui-input middput height" value="'+qing[key].height+'" placeholder="请输入" clearable autocomplete="off" >';
                    str += ' </div>';

                    str += '<div class="layui-input-block dankuai4" style=";margin-left: 0!important;">';
                    str += '<input type="text" class="layui-input middput floor_height" value="'+qing[key].floor_height+'" placeholder="请输入" clearable autocomplete="off" >';
                    str += ' </div>';

                    str += '</div></div></div>';
                }

                str += '<div class="layui-form-item"> <div class="layui-row layui-col-space10"><div class="layui-col-md12">';
                str += '<label class="layui-form-label">合计</label>';
                str += '<div class="layui-input-block dannav4" style=";margin-left: 0!important;">';
                str += '<span class="qingcount"></span>';
                str += ' </div>';
                str += '<div class="layui-input-block dankuai4" style=";margin-left: 0!important;">';
                str += ' </div>';
                str += '<div class="layui-input-block dankuai4" style=";margin-left: 0!important;">';
                str += ' </div>';
                str += '<div class="layui-input-block dankuai4" style=";margin-left: 0!important;">';
                str += ' </div>';
                str += '</div></div></div>';


                $("#qinginfo").html(str);

                countqing();

                render_from();
                initParseMoney();
            }
        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();
            if(!validRes){return false;}

            var list = [''];
            $('.area').each(function (i) {
                var id = $(this).attr('id');
                var area = $(this).val();
                var storey = $('.storey').eq(i).val();
                var height = $('.height').eq(i).val();
                var floor_height = $('.floor_height').eq(i).val();
                list.push({
                    id:id,
                    area:area,
                    storey:storey,
                    height:height,
                    floor_height:floor_height,
                })
            });
            data.field.list = list;

            data.field.id = param_id;
            data = parseMoney(data);
            facade.ajax({url: ask_main_gai_edit, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    facade.success("提交成功!");
                    setTimeout(() => {
                        window.location.reload();
                    }, 1500);
                }
            });

            return false;
        });

    });

    function countqing() {
        var count = 0;
        $('.area').each(function (i) {
            count += parseFloat($(this).val() || 0);
        });
        $(".qingcount").html(count);
        $("#mian").val(count);
    }
    

    //税金 = 含税价/（1+税率/100）*税率/100
    //不含税 = 含税价/（1+税率/100）
    function countTou() {
        var money = parseFloat($("#money").val() || 0) || 0;
        var rate = parseFloat($("#rate").val() || 0) || 0;

        var rate_money = money/(1+rate/100)*rate/100;
        rate_money = rate_money.toFixed(2);
        $("#rate_money").val(rate_money);

        var no_money = money/(1+rate/100)
        no_money = no_money.toFixed(2);
        $("#no_money").val(no_money);
    }


    function countShui() {
        var budget_money = parseFloat($("#budget_money").val() || 0) || 0;
        var budget_rate = parseFloat($("#budget_rate").val() || 0) || 0;

        var budget_rate_money = budget_money/(1+budget_rate/100)*budget_rate/100;
        budget_rate_money = budget_rate_money.toFixed(2);
        $("#budget_rate_money").val(budget_rate_money);

        var budget_no_money = budget_money/(1+budget_rate/100)
        budget_no_money = budget_no_money.toFixed(2);
        $("#budget_no_money").val(budget_no_money);
    }

</script>
</body>
</html>
